package com.wondersgroup.framework.widget.taglib.form;

import com.wondersgroup.framework.widget.annotations.WidgetTag;
import com.wondersgroup.framework.widget.annotations.WidgetTagAttribute;
import com.wondersgroup.framework.widget.library.extjs.ExtComponent;
import com.wondersgroup.framework.widget.library.extjs.form.ExtHtmlEditor;
import com.wondersgroup.framework.widget.library.html.Div;
import com.wondersgroup.framework.widget.library.html.HtmlComponent;
import com.wondersgroup.framework.widget.taglib.form.util.FormUtils;
import com.wondersgroup.framework.widget.util.OutputUtils;
import com.wondersgroup.framework.widget.util.TagUtils;
import com.wondersgroup.framework.widget.validation.annotation.TagValidate;
import com.wondersgroup.framework.widget.validation.annotation.TypeValidate;
import javax.servlet.jsp.JspException;
import org.springframework.beans.BeanUtils;

@WidgetTag(name = "htmlEditor", tldTagClass = "com.wondersgroup.framework.widget.taglib.form.HtmlEditorTag", description = "htmleditor构件是一个富文本编辑器，提供了较多的文字编辑功能")
@TagValidate
public class HtmlEditorTag extends BaseInputTag {

	@TypeValidate
	private boolean enableAlignments = true;

	@TypeValidate
	private boolean enableColors = true;

	@TypeValidate
	private boolean enableFont = true;

	@TypeValidate
	private boolean enableFontSize = true;
	private String fontFamilies;

	@TypeValidate
	private boolean enableFormat = true;

	@TypeValidate
	private boolean enableLinks = true;

	@TypeValidate
	private boolean enableLists = true;

	@TypeValidate
	private boolean enableSourceEdit = true;
	private String height = "0";
	private String width = "0";
	private String uploadUrl;

	public boolean isEnableAlignments() {
		return this.enableAlignments;
	}

	@WidgetTagAttribute(description = "启用工具栏对齐按钮(默认值为 true)")
	public void setEnableAlignments(boolean paramBoolean) {
		this.enableAlignments = paramBoolean;
	}

	public boolean isEnableColors() {
		return this.enableColors;
	}

	@WidgetTagAttribute(description = "启用工具栏回退/高亮颜色按钮(默认值为 true)")
	public void setEnableColors(boolean paramBoolean) {
		this.enableColors = paramBoolean;
	}

	public boolean isEnableFont() {
		return this.enableFont;
	}

	@WidgetTagAttribute(description = "启用工具栏字体选择。Safari下不可用。(默认值为 true)")
	public void setEnableFont(boolean paramBoolean) {
		this.enableFont = paramBoolean;
	}

	public boolean isEnableFontSize() {
		return this.enableFontSize;
	}

	@WidgetTagAttribute(description = "启用工具栏字体大小按钮。(默认值为 true)")
	public void setEnableFontSize(boolean paramBoolean) {
		this.enableFontSize = paramBoolean;
	}

	public String getFontFamilies() {
		return this.fontFamilies;
	}

	@WidgetTagAttribute(description = "用于选择的字体数组(JSON数组)")
	public void setFontFamilies(String paramString) {
		this.fontFamilies = paramString;
	}

	public boolean isEnableFormat() {
		return this.enableFormat;
	}

	@WidgetTagAttribute(description = "启用工具栏格式化按钮。(默认值为 true)")
	public void setEnableFormat(boolean paramBoolean) {
		this.enableFormat = paramBoolean;
	}

	public boolean isEnableLinks() {
		return this.enableLinks;
	}

	@WidgetTagAttribute(description = "启用创建链接按钮。 Safari下不可用。(默认值为 true)")
	public void setEnableLinks(boolean paramBoolean) {
		this.enableLinks = paramBoolean;
	}

	public boolean isEnableLists() {
		return this.enableLists;
	}

	@WidgetTagAttribute(description = "启用工具栏项目符号按钮。(默认值为 true)")
	public void setEnableLists(boolean paramBoolean) {
		this.enableLists = paramBoolean;
	}

	public boolean isEnableSourceEdit() {
		return this.enableSourceEdit;
	}

	@WidgetTagAttribute(description = "启用工具栏源代码切换按钮。Safari下不可用。(默认值为 true)")
	public void setEnableSourceEdit(boolean paramBoolean) {
		this.enableSourceEdit = paramBoolean;
	}

	public String getHeight() {
		return this.height;
	}

	@WidgetTagAttribute(description = "组件高度", required = true)
	public void setHeight(String paramInt) {
		this.height = paramInt;
	}

	public String getWidth() {
		return this.width;
	}

	@WidgetTagAttribute(description = "自定义组件宽度")
	public void setWidth(String paramInt) {
		this.width = paramInt;
	}

	public String getUploadUrl() {
		return this.uploadUrl;
	}

	@WidgetTagAttribute(description = "图片文件上传处理地址")
	public void setUploadUrl(String paramString) {
		this.uploadUrl = paramString;
	}

	public void processStartTagContent() throws JspException {
		Div localDiv = new Div(getId() + "_div");
		ExtHtmlEditor localExtHtmlEditor = new ExtHtmlEditor(getId());
		BeanUtils.copyProperties(this, localExtHtmlEditor);
		localExtHtmlEditor.setRenderTo(localDiv.getId());
		StringBuffer localStringBuffer = new StringBuffer();
		localStringBuffer.append(OutputUtils.writeHTML(new HtmlComponent[] { localDiv }));
		localStringBuffer.append(OutputUtils.ExtOnReady(new ExtComponent[] { localExtHtmlEditor }));
		FormUtils.addFieldsToForm(this.pageContext, localExtHtmlEditor);
		TagUtils.getInstance().write(this.pageContext, localStringBuffer.toString());
	}
}